<div class="modal-header">
	<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
	<h4 class="modal-title">修改投票信息</h4>
</div>
<div class="modal-body">
	<div class="row">
		<div class="col-lg-12">
			<div class="modal-header">
				<h5 class="col-lg-10">投票选项</h5>
				<div class="ibox-tools">
					<a th:href="@{/admin/m/ext/vote/addOption_{voteId}.gsp(voteId=${result.id})}" data-target="#commonOptionWin" class="btn btn-primary btn-xs" type="button" data-toggle="modal"><i class="fa fa-plus"></i>&nbsp;新增投票选项</a>
				</div>
			</div>
			<br />
			<div class="main-box-body clearfix">
				<table id="optionTable" cellspacing="0" width="100%" class="table table-striped table-hover ">
					<thead>
						<tr>
							<th>#</th>
							<th>投票标题</th>
							<th>得票数</th>
							<th>描述</th>
							<th>操作</th>
						</tr>
					</thead>
				</table>
			</div>
		</div>
	</div>
</div>
<form th:action="@{/admin/m/ext/vote/edit.gsp}" th:object="${result}" id="editForm" class="form-horizontal" role="form" action="#" method="post">
	<div class="modal-body">
		<div class="row">
			<div class="col-md-12">
				<input th:field="*{id}" type="text" hidden="true" />
				<div class="form-group">
					<label class="col-md-2 control-label">投票标题<label class="text-danger">*</label>：
					</label>
					<div class="col-md-10">
						<input th:field="*{title}" placeholder="请输入投票标题" type="text" class="form-control" />
					</div>
				</div>
				<div class="form-group">
					<label class="col-md-2 control-label">模 式<label class="text-danger">*</label>：
					</label>
					<div class="col-md-4">
						<select th:field="*{voteMode}" class="form-control">
							<option value="1">独立访客</option>
							<option value="2">独立IP</option>
							<option value="3">独立用户</option>
						</select>
					</div>
					<label class="col-md-2 control-label">投票编码<label class="text-danger">*</label>：
					</label>
					<div class="col-md-4">
						<input th:field="*{codeNum}" placeholder="请输入投票编码" type="text" class="form-control" />
					</div>
				</div>
				<div class="form-group">
					<label class="col-md-2 control-label">开始时间<label class="text-danger">*</label>：
					</label>
					<div class="col-md-4">
						<div class="input-group date">
							<input th:field="*{startTime}" id="startTime" readonly="readonly" type="text" class="form-control" /> <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
						</div>
					</div>
					<label class="col-md-2 control-label">结束时间：</label>
					<div class="col-md-4">
						<div class="input-group date">
							<input th:field="*{endTime}" readonly="readonly" type="text" class="form-control" /> <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
						</div>
					</div>
				</div>
				<div class="form-group">
					<label class="col-md-2 control-label">间隔天数<label class="text-danger">*</label>：
					</label>
					<div class="col-md-4">
						<input th:field="*{intervalDays}" placeholder="请输入间隔天数" type="text" class="form-control" />
					</div>
					<label class="col-md-2 control-label">最多可选项<label class="text-danger">*</label>：
					</label>
					<div class="col-md-4">
						<input th:field="*{maxSelected}" placeholder="请输入最多可选项" type="text" class="form-control" />
					</div>
				</div>
				<div class="form-group">
					<label class="col-md-2 control-label">描 述：</label>
					<div class="col-md-10">
						<textarea th:field="*{description}" placeholder="最多输入140字" class="form-control"></textarea>
					</div>
				</div>
			</div>
		</div>
	</div>
	<div class="modal-footer">
		<button class="btn btn-primary" type="submit">
			<strong>提 交</strong>
		</button>
		<button type="button" class="btn btn-default" data-dismiss="modal">
			<strong>关 闭</strong>
		</button>
	</div>
</form>
<!--/* 模板引擎生成数据 */-->
<script th:inline="javascript">
    $('.date').datepicker({
        todayBtn : "linked",
        keyboardNavigation : false,
        forceParse : false,
        initialDate : new Date(),
        altField : '#actualDate',
        calendarWeeks : true,
        autoclose : true
    });
    /*<![CDATA[*/
    var optionColumnDefs = [ {
        //第一列，用来显示序号
        "searchable" : false,
        "orderable" : false,
        "targets" : 0
    } ];
    var optionColumns = [ {
        //第一列，用来显示序号
        "data" : null
    },{
    	"data" : "title"
    },{
        "data" : "voteCount"
    },{
        "data" : "description"
    },{
        "data" : null, //最后一列，操作按钮
        render : function(data, type, row, meta) {
            var editUrlPre= /*[[@{/admin/m/ext/vote/editOption_}]]*/'url';
            var editUrlPath = editUrlPre + row.id +'.gsp';
            var result = '';        
            //修改按钮
            result += ' <a href="'+editUrlPath+'" data-target="#commonOptionWin" data-toggle="modal" class="btn btn-primary btn-xs"><i class="fa fa-pencil"></i></a>';
            //删除按钮
            result += ' <a href="#" type="button" onclick="myOptionTable.deleteItem(\'' + row.id + '\')" class="btn btn-danger btn-xs"><i class="fa fa-trash-o"></i></a>';    
            return result;
        } 
    } ];
  //ajax参数
    var optionAjaxDataParamFun = function(d) {
    };
    var optionSetting = {
        listUrl : /*[[@{/admin/m/ext/vote/OptionList_{voteId}.gsp(voteId=${result.id})}]]*/'url',
        deleteUrl : /*[[@{/admin/m/ext/vote/deleteOption_}]]*/'url',
        enabledChange : true, //修改是否可用
        columnDefs : optionColumnDefs, //表格列定义
        columns : optionColumns, //表格列
        dataTableDiv : 'optionTable', //表格
        ajaxDataParamFun : optionAjaxDataParamFun, //ajax参数
        pageable : false, //是否分页
        showIndexColumn : true, //是否显示第一列的索引列
        enabledChange : true
    };
    var myOptionTable = new TG_Tabel.createNew(optionSetting);
    $(function() {
        $("#startTime").val(new Date().Format("yyyy-mm-dd"));
        var rules = {
            title : {
                required : true,
                maxlength : 40
            },
            codeNum : {
                required : true,
                maxlength : 20,
                minlength : 2
            },
            intervalDays : {
                required : true,
                digits : true,
                max : 999,
                min : 1
            },
            maxSelected : {
                required : true,
                digits : true,
                max : 20,
                min : 0
            },
            description : {
                maxlength : 140
            }
        }
        var messages = {

        }
        myTable.add('commonWin', 'editForm', rules, messages);
        myOptionTable.init();
    });
    /*]]>*/
</script>
